<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class asesoria extends MY_Controller {

    /**
     * Evita la validacion (enfocado cuando se usa ajax). Ver mas en privilegios_model
     * @var unknown_type
     */
    private $excepcion_privilegio = array('');

    public function _remap($method){
      $this->carabiner->css(array(
          array('libs/jquery-ui.css', 'screen'),
          array('libs/ui.notify.css', 'screen'),
          array('libs/jquery.treeview.css', 'screen'),
          array('base-panel.css', 'screen')
      ));
      $this->carabiner->js(array(
          array('libs/jquery.min.js'),
          array('libs/jquery-ui.js'),
          array('libs/jquery.notify.min.js'),
          array('libs/jquery.treeview.js'),
          array('general/alertas.js')
      ));

      $this->load->model("empleados_model");
      if($this->empleados_model->checkSession()){
        // $this->empleados_model->excepcion_privilegio = $this->excepcion_privilegio;
        // $this->info_empleado = $this->empleados_model->getInfoEmpleado($_SESSION['id_empleado'], true);
        $this->{$method}();
      }else
        redirect(base_url('panel/home/'));
    }

    public function index()
    {
        redirect(base_url('panel/home/'));
    }

    public function modificar()
    {
      $this->configAsesoria();
      if ($this->form_validation->run() == FALSE)
      {
        $params['frm_errors'] = $this->showMsgs(2, preg_replace("[\n|\r|\n\r]", '', validation_errors()));
      }
      else
      {
        $this->load->model('asesoria_model');
        $mdl_res = $this->asesoria_model->modificaInformacion();

        $params['frm_errors'] = $this->showMsgs(4);
      }

      if (isset($_GET['msg']))
        $params['frm_errors'] = $this->showMsgs($_GET['msg']);

      echo json_encode($params['frm_errors']);
    }

    public function configAsesoria()
    {
      $this->load->library('form_validation');
      $rules = array(
          array('field' => 'fnombre',
                'label' => 'Nombre',
                'rules' => 'required|max_length[80]'),
          array('field' => 'fpuesto',
                'label' => 'Puesto',
                'rules' => 'required|max_length[60]'),
          array('field' => 'ftelefono',
                'label' => 'Telefono',
                'rules' => 'required|max_length[25]'),
         array('field'  =>'femail',
                'label' => 'Email',
                'rules' => 'required|max_length[70]|valid_email'),
         array('field'  =>'ftitulo',
                'label' => 'Titulo',
                'rules' => 'required|max_length[22]')
        );

      $this->form_validation->set_rules($rules);
    }

    private function showMsgs($tipo, $msg='', $title='Usuarios')
    {
      switch($tipo){
        case 1:
          $txt = 'El campo ID es requerido.';
          $icono = 'error';
          break;
        case 2: //Cuendo se valida con form_validation
          $txt = $msg;
          $icono = 'error';
          break;
        case 3:
          $txt = 'La informacion se agregó correctamente.';
          $icono = 'success';
          break;
        case 4:
          $txt = 'La informacion se modificó correctamente.';
          $icono = 'success';
          break;
        case 5:
          $txt = 'La informacion se eliminó correctamente.';
          $icono = 'success';
          break;
        case 6:
          $txt = 'La informacion se activó correctamente.';
          $icono = 'success';
          break;
      }

      return array(
          'title' => $title,
          'msg' => $txt,
          'ico' => $icono);
    }

}

/* End of file precios.php */
/* Location: ./application/controllers/panel/precios.php */
